#include "StdAfx.h"

Hud* Singleton<Hud>::m_instance = 0;

Hud::Hud() : m_text("Fonts\\FrizQT__.ttf", "Friz Quadrata TT", 10, 20, true)
{
	m_szCurText = L"";
	m_textSet = 0;
	m_duration = 0;
}

void Hud::Draw()
{
	if(sD3D.GetAppState() != STATE_WORLD && sD3D.GetAppState() != STATE_MINIMAP && sD3D.GetAppState() != STATE_MENU)
		return;
	if(m_szCurText != L"")
	{
		ui32 diff = GetTickCount() - m_textSet;
		if(diff > m_duration)
		{
			m_szCurText = L"";
			m_textSet = 0;
			return;
		}

		ui8 alpha = 255;
		static const float alphaLoss = 255.0f / 1500.0f;

		if(m_duration - diff < 1500)
		{
			ui32 loss = 1500 + diff - m_duration;
			loss = (ui32)floor(loss * alphaLoss);
			if(loss > 255)
				loss = 255;
			if(loss == 255)
			{
				m_szCurText = L"";
				m_textSet = 0;
				return;
			}
			alpha = 255 - loss;
		}

		ui32 textDiff = m_text.GetTextLenW(m_szCurText, true) / 2;
		m_text.DrawTextW((sD3D.GetSize().x / 2) - textDiff, 200, m_text.GetTextLenW(m_szCurText), 30, m_szCurText, m_color | (alpha << 24));
	}
}